﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR.Core;

namespace FunctionalCLR.Shell.Function.Flow {
    public class ForNode : FuncNode {

        public ForNode()
            : base() {
            base.Value = "for";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            string cond = Children[0].Evaluate().ToString();
            string result = string.Empty;

            while (cond.ToLower().Equals("true")) {
                try {
                    Children[1].Evaluate();
                    result = Children[0].Evaluate().ToString();
                } catch (BreakException ex) {
                    break;
                }
            }

            return result;
        }
    }
}
